<?php
// 应用公共文件

/**
 * todo 统一返回格式
 * @param $status
 * @param $msg
 * @param $datas
 * @param $pageInfo
 * @return \think\response\Json
 */
function responseData(
    $status = true,
    $msg = "",
    $datas = null,
    $pageInfo = null
)
{
    $response = ['code' => 0, 'msg' => $msg];
    if (!$status) {
        $response['code'] = 1;
    }
    $response['data'] = $datas;
    if ($pageInfo) {
        $response['pageInfo'] = $pageInfo;
    }

    return json($response);
}


// 自定义日志模块
const LOG_LEVEL_ERROR = 'error';
const LOG_LEVEL_INFO = 'info';
const LOG_LEVEL_DEBUG = 'debug';
const LOG_LEVEL_NOTICE = 'notice';
/**
 * ## 自定义日志
 * @param $level
 * @param $className
 * @param mixed $msg
 * @return void
 */
function selfLog($level, $className, $msg)
{
    $errMsg = "\nClassName:$className \n";
    if ($msg instanceof \Exception) {
        $exception = $msg;
        $errMsg .= $exception->getMessage() . "\n";
        $errMsg .= $exception->getFile() . ":" . $exception->getLine() . "\n";
    } else {
        $msg = json_encode($msg, JSON_UNESCAPED_UNICODE);
        $errMsg .= "$msg \n";
    }
    trace($errMsg, $level);
}